package cn.netjava.softkid.chapter09;

public class MonitorThread implements Runnable{
	private java.util.List<FindFileUseMutiThread> list;
	private boolean stop;
	public MonitorThread(java.util.List<FindFileUseMutiThread> list)
	{
		this.list=list;
		stop=false;
	}
	public void run()
	{
		java.util.List<FindFileUseMutiThread> results = new java.util.ArrayList();
		while(!stop){
		for(int i=0;i<list.size();i++)
		{
			FindFileUseMutiThread f = list.get(i);
			if(f.isStop())
			{
				results.addAll(f.getList());
				list.remove(i);
				System.out.println("a thread was stop!");
			}
			
		}
		if(list.size()==0)
			stop=true;
		}
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		for(int i=0;i<results.size();i++)
		{
			System.out.println(results.get(i));
		}
		System.out.println("all thread had already done!");
			
	}
}
